package BinaryTree;
/*
 * 对称二叉树
 */
import BinaryTree.init.TreeNode;

public class lc101 {
    public boolean isSymmetric(TreeNode root) {
        return compare(root.left, root.right);
    }
    public boolean compare(TreeNode left, TreeNode right) {

        if (left == null && right != null) return false;
        if (left != null && right == null) return false;
        if (left == null && right == null) return true;
        if (left.val != right.val) return false;

        boolean outside =  compare(left.left, right.right);
        boolean inside = compare(left.right, right.left);
        boolean res = outside && inside;
        
        return res;
    }
}
